/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package calendar;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 *  备忘
 * @author 啊正
 */
public class CheckMemo {

    private File file = null;
    private String path = "D:/Calendar_Memo/Memo.BOX";
    private String date = "";
    private int tadayCount = 0;
    private int allCount = 0;
    private static String tadayMemo = "";
    private static String allMemo = "";

    public CheckMemo(){       
    }
    
    public CheckMemo(String date) {
        this.date = date;
        this.start();
    }

    public void start() {
        String readFile = new String();
        if (file == null) {
            file = new File(path);
        }
        if (!file.exists()) {
            try {
                System.out.println("------文件不存在,系统将自动创建------");
                file.getParentFile().mkdirs();
                file.createNewFile();
            } catch (IOException ex) {
                System.out.println("------" + ex.getMessage() + "------");
                return;
            }
        }
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
            tadayMemo="";
            allMemo="";
            tadayCount=0;
            allCount=0;
            while ((readFile = br.readLine()) != null) {
                String[] str = readFile.split(",");
                if (str[0].equals(date)) {
                    tadayMemo+=readFile+"_";
                    tadayCount++;
                }
                allMemo+=readFile+"_";
                allCount++;
            }
            MyCalendar.labCount.setText("<html><div align='center'><font corlor='black'>该天备忘录：</font><font color='red'>"+
                    tadayCount + "个</font></div></html>");
            MyCalendar.labAllCount.setText("<html><div align='center'><font color='black'>全部备忘录：</font><font color='red'>" +
                    allCount+"个</font></div></html>");
        } catch (Exception e) {
        }
    }

    public String getTadayMemo() {
        return tadayMemo;
    }

    public String getAllMemo() {
        return allMemo;
    }
}
